/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef IMAGE_KNIFE_C_FILE_CACHE_INTERCEPTOR_OH_H
#define IMAGE_KNIFE_C_FILE_CACHE_INTERCEPTOR_OH_H

#include "interceptor.h"
#include "imageknife_request.h"
#include "file_cache.h"
#include "imageknife_internal.h"
#include "imageknife_data_napi.h"
#include "utils/file_type_util.h"

namespace ImageKnifePro {
class FileCacheInterceptorDefault : public FileCacheInterceptor {
public:
    FileCacheInterceptorDefault();
    ~FileCacheInterceptorDefault();
    static std::shared_ptr<FileCacheInterceptorDefault> GetInstance();

    bool Resolve(std::shared_ptr<ImageKnifeTask> task) override;

    CacheErrorCode AddSmallEndFileCache(std::string cacheName, std::string filePath);

    void SetBigEndFilePath(std::string filePath);

    void Init(std::string cacheName);
    bool IsInitFinished(std::string cacheName);
    int64_t GetCurrentCacheNum(std::string cacheName);
    int64_t GetCurrentCacheSize(std::string cacheName);
    int64_t GetLimitSize(std::string cacheName);
    int64_t GetLimitNum(std::string cacheName);
    void SetLimit(size_t maxSize, size_t maxUsage, std::string cacheName);
    void PackPixelmapToFile(std::string filePath, OH_PixelmapNative *pixelmap, std::string cacheName);

    void EnableExtension(std::string cacheName);
    void RemoveFile(std::string filePath, std::string cacheName);
    void RemoveAllFile(std::string cacheName);
private:
    FileCache fileCache_;
    std::string bigEndFilePath_;
    std::unordered_map<std::string, FileCache *> fileCacheMap_;

    FileCache *GetFileCacheByName(const std::string &cacheName);
    bool Read(std::shared_ptr<ImageKnifeTaskInternal> task, FileCache *fileCache);

    bool Write(std::shared_ptr<ImageKnifeTaskInternal> task, FileCache *fileCache);
};
};

#endif // IMAGE_KNIFE_C_FILE_CACHE_INTERCEPTOR_OH_H
